package com.ldpp.backengine;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;
import com.ldpp.common.base.TradeStr;
import com.ldpp.entity.TickMin;
import com.ldpp.entity.VtTradeData;
import com.ldpp.strategy.strategy_1;
import com.lmax.disruptor.EventHandler;

import java.util.List;

/**
 * @author ：gongtan
 * @date ：Created in 2021/3/16 13:38
 * @description：　消费者处理
 * @modified By：
 */
public class BackHandler implements EventHandler<TickMin> {

    //账户收益  用于生成策略曲线
    private List<Double> profitPrice;

    //仓位   用于计算收益
    private List<VtTradeData> position;


    strategy_1 strategy_1 = new strategy_1();

    @Override
    public void onEvent(TickMin tickMin, long l, boolean b) throws Exception {
        //拿到 Tick 的数据 进入策略处理
        //System.out.println("消费者处理数据"+tickMin.toString() +"long 类型数值" +l);
        //处理逻辑在此方法内被调用

        JSONObject jsonObject = strategy_1.strategyHandler(tickMin);
        if(jsonObject != null){
            opean_position(jsonObject.getString("direction"),
                    jsonObject.getDouble("price"),
                    jsonObject.getString("symbol"),
                    jsonObject.getString("offset"),
                    jsonObject.getInteger("volume"),
                    jsonObject.getString("tradeTime"));
        }
    }


    /**
     * 开平
     * @param direction 方向
     * @param price   成交价格
     * @param symbol  合约代码
     * @param offset 开平标志
     */
    public void opean_position(String direction, double price, String symbol, String offset, Integer volume, String data){
        VtTradeData vtTradeData = new VtTradeData();
        vtTradeData.setOffset(offset);
        vtTradeData.setDirection(direction);
        vtTradeData.setPrice(price);
        vtTradeData.setSymbol(symbol);
        vtTradeData.setTradeTime(data);
        vtTradeData.setVolume(volume);
        System.out.println(vtTradeData);
    }
}
